package com.cx.caigou.request.mapper;

import com.cx.caigou.config.ResultVO;
import com.cx.caigou.request.model.*;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.HashSet;
import java.util.List;

@Mapper
public interface RequestMapper {

    @Select("SELECT * from legalperson where userId = #{id}")
    List<LegalPersonVO> query(Integer id);

    List<String> queryByLegalPerson(Integer id);

    List<RequestClass> queryData(RequestSelect requestSelect);

    int queryCount(RequestSelect requestSelect);


    List<SpareClass> querySpareData(SelectSpare selectSpare);

    int querySpareCount(SelectSpare selectSpare);

    List<SupplierClass> querySupplierData(SelectSupplier selectSupplier);

    int querySupplierCount(SelectSupplier selectSupplier);

    List<SeeClass> queryByRequestId(Integer requestForQuotationId);

    @Select("select * from legalPerson where legalPersonId = #{id}")
    List<LegalPersonVO> queryLegalPerson(int legalPersonImd);

    @Select("select * from spare where spareName = #{spareName} and spareCode =#{spareCoding}")
    ResultVO querySpare(List inquiryDetailsList);

    void addTou(AllClass allClass);

    void addSpare(List inquiryDetailsList,int requestForQuotationId,int spareId);

    void addSupplier(List supplierDetailsList,int requestForQuotationId,int supplierId);

    @Select("select * from request_spare where requestForQuotationId = #{requestForQuotationId}")
    List<SpareVo> queryInquiryDetailsList(Integer requestForQuotationId);

    @Select("select s.supplierId vendorId,s.supplierName vendor,s.supplierCode vendorCode from supplier s\n" +
            "LEFT JOIN request_supplier rs on rs.supplierId = s.supplierId\n" +
            "where rs.requestForQuotationId = #{requestForQuotationId}")
    List<SupplierVo> querySupplierDetailsList(Integer requestForQuotationId);

    @Select("select spare.spareCode code,spare.spareName name from spare where spare.spareId = #{id}")
    List<SpareClass> queryspare(Integer id);

    void updateTou(AllClass allClass);

    void deleteAllSpare(List inquiryDetailsList, int requestForQuotationId);

    void addAllSpare(List inquiryDetailsList, int requestForQuotationId);

    void deleteAllSupplier(List supplierDetailsList, int requestForQuotationId);

    void addAllSupplier(List supplierDetailsList, int requestForQuotationId);

    @Select("select spareCoding from request_spare ")
    List<String> queryCode();

    @Select("select spareName from request_spare")
    List<String> queryName();

    void addAll(RequestSpare list);

    @Update("update tou set inquiryStatus = 4 where requestForQuotationId = #{requestForQuotationId}")
    void modifyState(ID requestForQuotationId);

    @Update("update tou set inquiryStatus = 2 where requestForQuotationId = #{requestForQuotationId}")
    void updateState(ID requestForQuotationId);

    @Update("update tou set inquiryStatus = 0 where requestForQuotationId = #{requestForQuotationId}")
    void approverState(ID requestForQuotationId);

    @Select("select count(requestForQuotationId) from tou where requestForQuotationId = #{r}")
    int  queryIsFind(int r);


    List<Integer> querySpareId(List<String> codeSpares);

    List<String> queryBeiAllCode(HashSet<Integer> spareIds);

    List<Integer> querySupplierId(List<String> codeSupplier);

    List<String> queryGongAllCode(HashSet<Integer> supplierIds);

    List<SpareSupplier> queryPSByCodes(HashSet<Integer> spareIds);
}
